package org.chl.chapter05.controller;

import java.util.List;

import org.chl.chapter05.dao.BookDao;
import org.chl.chapter05.model.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/book")
public class BookController {

	@Autowired
	BookDao bookDao;

	@PostMapping("addBook")
	public int addBook(@RequestBody Book book) {
		return bookDao.addBook(book);
	}

	@PostMapping("updateBook")
	public int updateBook(@RequestBody Book book) {
		return bookDao.updateBook(book);
	}

	@GetMapping("deleteBookByid")
	public int deleteBookByid(Integer id) {
		return bookDao.deleteBookByid(id);
	}

	@GetMapping("getBookByid")
	public Book getBookByid(Integer id) {
		return bookDao.getBookByid(id);
	}

	@GetMapping("getAllBooks")
	public List<Book> getAllBooks() {
		return bookDao.getAllBooks();
	}
}
